
layui.use(['jquery','febs', 'form', 'validate', 'treeSelect', 'eleTree'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        eleTree = layui.eleTree,
        form = layui.form,
        $view = $('#tenant-detail'),
        // $scale = $('div[name="scale"]'),
        $attribute = $('div[name="attribute"]'),
        $economyType = $('div[name="economyType"]'),
        $economyMajorType = $('div[name="economyMajorType"]'),
        $economyMinorType = $('div[name="economyMinorType"]'),
        $industryTradeType = $('div[name="industryTradeType"]'),
        $inherentLevel = $('div[name="inherentLevel"]'),
        $reachCondition = $('div[name="reachCondition"]'),
        $trafficReachCondition = $('div[name="trafficReachCondition"]'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    form.disabled = true;
    initDictItemLabel_tenantDetail();
    function initDictItemLabel_tenantDetail(){
        // febs.initDictItemLabel($scale,'SAFETY_COMPANY_SCALE',tenant.scale);
        febs.initDictItemLabel($attribute,'SAFETY_COMPANY_ATTRIBUTE',tenant.attribute);
        febs.initDictItemLabel($economyType,'SAFETY_ECONOMY_TYPE',tenant.economyType);
        febs.initDictItemLabel($economyMajorType,'SAFETY_ECONOMY_MAJOR_TYPE',tenant.economyMajorType);
        febs.initDictItemLabel($economyMinorType,'SAFETY_ECONOMY_MINOR_TYPE',tenant.economyMinorType);
        febs.initDictItemLabel($industryTradeType,'SAFETY_INDUSTRY_TRADE_TYPE',tenant.industryTradeType);
        febs.initDictItemLabel($inherentLevel,'SAFETY_INHERENT_LEVEL',tenant.inherentLevel);
        febs.initDictItemLabel($reachCondition,'SAFETY_REACH_CONDITION',tenant.reachCondition);
        febs.initDictItemLabel($trafficReachCondition,'SAFETY_REACH_CONDITION',tenant.trafficReachCondition);
    }

    var menuTree = eleTree.render({
        elem: '.menu-tree',
        url: ctx + 'menu/treeForTopLevel',
        where: {
            "invalidate_ie_cache": new Date()
        },
        showCheckbox: true,
        accordion: false,
        checkStrictly: false,
        renderAfterExpand: false,
        request: {
            name: "title",
            key: "id",
            children: "childs",
            checked: "checked",
            data: "data"
        },
        response: {
            statusName: "code",
            statusCode: 200,
            dataName: "data"
        },
        done: function (data) {
            if (tenant) {
                setTimeout(initFormValue, 100);
            }
        }
    });

    initFormValue();

    function initFormValue() {
        if (tenant) {
            form.val("tenant-edit-form", {
                "tenantId": tenant.tenantId,
                "tenantName": tenant.tenantName,
                "shortName": tenant.shortName,
                "contact": tenant.contact,
                "contactNumber": tenant.contactNumber,
                "address": tenant.address,
                "appId": tenant.appId,
                "appSecret": tenant.appSecret,
                "utype": tenant.utype
            });
            if (tenant.menuIds) {
                menuTree.setChecked(tenant.menuIds.split(','), true);
            } else {
                menuTree.setChecked([], true);
            }
        }
    }

});
